package nc.ui.mlr.m400641;

import java.util.ArrayList;

import nc.ui.mlr.pub.MLRProxy;
import nc.ui.pf.pub.PfUIDataCache;
import nc.vo.mlr.m400641.SalebillHVO;
import nc.vo.pub.SuperVO;
import nc.vo.pub.billtype.BilltypeVO;

public class BusinessDelegator extends nc.ui.trade.bsdelegate.BusinessDelegator {

	@Override
	public SuperVO[] queryHeadAllData(Class headClass, String strBillType,
			String strWhere) throws Exception {
		BilltypeVO billVo = PfUIDataCache.getBillType(strBillType);
		if (billVo.getWherestring() != null
				&& billVo.getWherestring().length() != 0) {
			if (strWhere != null)
				strWhere = strWhere + " and (" + billVo.getWherestring() + ")";
			else
				strWhere = billVo.getWherestring();
		}
		strWhere = nc.vo.mlr.pub.ToolKit.DeleteBusitype(strWhere);
		String sql = "select distinct mlr_salebill_b.pk_salebill_h from mlr_salebill_b inner join mlr_salebill_h on mlr_salebill_b.pk_salebill_h = mlr_salebill_h.pk_salebill_h and "
				+ strWhere;
		if (sql.contains("pk_corp"))
			sql = sql.replace("pk_corp", "mlr_salebill_h.pk_corp");
		if (sql.contains("dr"))
			sql = sql.replace("dr", "mlr_salebill_h.dr");
		sql = sql.concat(" and isnull(mlr_salebill_b.dr,0)=0 ");

		ArrayList<SalebillHVO> al = (ArrayList<SalebillHVO>) MLRProxy
				.getIUAPQueryBS().retrieveByClause(headClass,
						"pk_salebill_h in (" + sql + ") ");
		// return HYPubBO_Client.queryByCondition(headClass, strWhere);
		return al.toArray(new SalebillHVO[al.size()]);
	}
}
